package cn.azzhu.day01

import org.apache.flink.streaming.api.scala._

/**
 * @author azzhu
 * @create 2020-09-17 21:48:22
 */
object StreamScalaWordCount {
  def main(args: Array[String]): Unit = {
    //todo 1.获取执行环境
    val env = StreamExecutionEnvironment.getExecutionEnvironment

    //todo 2.获取source
    val lines = env.socketTextStream(args(0), args(1).toInt)

    //todo 3.transformation
    val words = lines.flatMap(_.split(" "))

    val wordAndOne = words.map((_, 1))

    val sumed = wordAndOne.keyBy(0).sum(1)

    sumed.print()

    env.execute("StreamWordCount")
  }
}
